#include "CheckPingThread.h"
#include "ServerManager.h"

#include <iostream>

CheckPingThread::CheckPingThread()
{
	m_checkTimer = 0;
	m_syncTimer = 0;
}

void CheckPingThread::Work()
{
	MutexLocker ml(&m_mutex);

	while(true)
	{
		m_timer.UpdateTime();
		unsigned int dt = m_timer.GetDtMS();
		m_checkTimer += dt;
		m_syncTimer += dt;
		//std::cout << "pingthread dt: " << TheTimerMS::Instance()->GetDtMS() << std::endl;
		if (m_checkTimer > 1000)
		{
			// call server checkmaxping function
			m_checkTimer = 0;
			TheServerManager::Instance()->CheckPing();
			std::cout << "pingthread checkTimer: " << m_checkTimer << std::endl;
			// update player positions
			//TheServerManager::Instance()->SyncPositions();
		}
		if (m_syncTimer > 10000)
		{
			m_syncTimer = 0;
			TheServerManager::Instance()->SyncTimers();
			std::cout << "pingthread synctimer: " << m_syncTimer << std::endl;
		}

	}
}